package com.asia5b.a5mall.order.adapter

import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
import com.asia5b.a5bmall.resource.ActCons
import com.asia5b.a5mall.middleware.model.order.OrderDetailModel
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.utils.CurrencyPriceBuilder3
import com.asia5b.a5mall.middleware.utils.push
import com.asia5b.a5mall.order.R
import com.asia5b.a5mall.order.activity.OrderDetail2Activity
import com.asia5b.a5mall.order.databinding.ItemOrderdetailGoods3adapterBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/5/9.
 */
class OrderDetailGoods3Adapter(var list: ArrayList<AbsGoodsModel>,var mactivity: OrderDetail2Activity) :
        BaseQuickAdapter<AbsGoodsModel, BaseDataBindingHolder<ItemOrderdetailGoods3adapterBinding>>(R.layout.item_orderdetail_goods3adapter, list) {


    override fun convert(helper: BaseDataBindingHolder<ItemOrderdetailGoods3adapterBinding>, item: AbsGoodsModel) {
        val itemOrderdetailGoods3adapterBinding = helper.dataBinding!!
        itemOrderdetailGoods3adapterBinding.model = item

        helper.setText(R.id.tv_foot_goodsnum, "x ${item.absGoodsCurrentBuyNum}")

        //价格
        val tv_foot_price = helper.getView<TextView>(R.id.tv_foot_price)
        val priceText = CurrencyPriceBuilder3().run {
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            buildPriceText()
        }
        tv_foot_price.text = priceText

        val allow_apply_service = item.absGoodsAction?.allow_apply_service ?: false
        helper.setGone(R.id.tv_orderdetail_aftersale, !allow_apply_service)
        helper.getView<TextView>(R.id.tv_orderdetail_aftersale)
                .setOnClickListener {
                    if (context is AppCompatActivity) {
                        (context as AppCompatActivity).push(ActCons.OrderAfterSaleActivity, {
                            it.withString("orderSn", mactivity.orderDetailModel.sn)
                            it.withInt("skuId", item.absGoodsSkuId)
                        })
                    }
                }
    }
}